const Preload = require('./preload');
class Ready extends Preload {
  constructor() {
    super();
    this.timeGroup = {};
    this.numGroup = {};
    this.gameTime = 15;
    this.gameNum =0;
    this.rules = `15秒之内获得30个元宵
    才可以抢红包哟
    点击屏幕开始游戏`
    this.mans=null;
  }
  setBg() {
    let bg = game.add.image(0, 0, 'bg_playing');
    bg.width = this.bw;
    bg.height = this.bh;
  }
  setTime() {
    this.timeGroup = game.add.group();
    this.timeGroup.x = 36;
    let bg = this.timeGroup.create(0, 0, 'btn_time');
    this.timeGroup.y = this.bh - bg.height - 40;
    let txt1 = game.add.text(24, 43, '剩余', { fontSize: 34, fill: '#720E0E' }, this.timeGroup);
    let txt2 = game.add.text(178, 43, '秒', { fontSize: 34, fill: '#720E0E' }, this.timeGroup);
    let txtBg = this.timeGroup.create(104, 35, 'bg_txt');
    let time = game.add.text(135, 43, this.gameTime, { fontSize: 34, fill: '#720E0E' }, this.timeGroup);
    time.anchor.setTo(0.5, 0);
    console.log(this.timeGroup.getAt(4));
  }
  setNum() {
    this.numGroup = game.add.group();
    let bg = this.numGroup.create(0, 0, 'btn_num');
    this.numGroup.x = this.bw - bg.width - 36;
    this.numGroup.y = this.bh - bg.height - 40;
    let txt = game.add.text(92, 50, 'x ' + this.gameNum, { fontSize: 34, fill: '#720E0E' }, this.numGroup);
  }
  setBeanMan() {
    let mans = game.add.group();
    let role1 = mans.create(this.bw / 2, this.setY(114), 'player_man');
    role1.anchor.setTo(0.5, 0);
    role1.z = 100;
    // let txt=mans.create(this.bw/2,this.setY(114)+role1.height,)
    // let bg=game.add.
    let cube = game.add.graphics(0, 0);
    console.log(cube)
    cube.beginFill("0x720e0e", 0.9);
    cube.drawRoundedRect((this.bw / 2) - 146, role1.y + role1.height - 10, 292, 137, 10);
    mans.add(cube);
    let txt = game.add.text(this.bw / 2, role1.y + role1.height + 10, this.rules, { fontSize: 26, fill: '#fff' }, mans);
    txt.anchor.setTo(0.5, 0);
    role1.bringToTop();
    this.mans=mans;
  }
  create() {
    this.setBg();
    this.setTime();
    this.setNum();
    this.setBeanMan();
    game.input.onDown.add(v=>{
      game.state.start('Playing');
    })
  }
}

module.exports = Ready;